<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" href="${ctx}/css/common.css" />
<link rel="stylesheet" href="${ctx}/css/validate.css" />
<link rel="stylesheet" href="${ctx}/css/dialog/skin/bluebar/ymPrompt.css" />

<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/dialog/ymPrompt.js"></script>

<script language="javascript">
<c:if test="${result == 'Success'}">
ymPrompt.succeedInfo("<s:text name='UpdatePasswordSuccess' />！",null,null,null,close);
</c:if>

$(document).ready(function() {
	$("#oldPassword").focus();
});

//对话框回调方法
function close(tp){
	if(tp=="ok"){
		$("#mainFrame",window.parent.document).attr("src","accountManagerPage.action");
		parent.ymPrompt.close();
	}
}

//关闭对话框
function closeWin(){
	parent.ymPrompt.close();
}

function formSubmit(){
	if(checkForm()){
		$("#submitForm").submit();
	} else {
		return false;
	}
}

function checkForm(){
	var oldPasswordFlag = true;
	var newPasswordFlag = true;
	var confirmPasswordFlag = true;
	var towPasswordFlag = true;
	
	if($("#oldPassword").val().replace(/\s+/g,'') == ""){
		$("#oldPassword").addClass("error");
		$("#oldPasswordErrMsg").text("<s:text name='OldPasswordIsNull' />");
		oldPasswordFlag = false;
	} else {
		$("#oldPassword").removeClass("error");
		$("#oldPasswordErrMsg").text("*");
		oldPasswordFlag = true;
	}
	
	if($("#newPassword").val().replace(/\s+/g,'') == ""){
		$("#newPassword").addClass("error");
		$("#newPasswordErrMsg").text("<s:text name='NewPasswordIsNull' />");
		newPasswordFlag = false;
	} else {
		$("#newPassword").removeClass("error");
		$("#newPasswordErrMsg").text("*");
		newPasswordFlag = true;
	}
	
	if($("#confirmPassword").val().replace(/\s+/g,'') == ""){
		$("#confirmPassword").addClass("error");
		$("#confirmPasswordErrMsg").text("<s:text name='ConfirmPasswordIsNull' />");
		confirmPasswordFlag = false;
	} else if($("#confirmPassword").val() != $("#newPassword").val()){
		$("#confirmPassword").addClass("error");
		$("#confirmPasswordErrMsg").text("<s:text name='TwoPasswordIsNoSame' />");
		towPasswordFlag = false;
	} else {
		$("#confirmPassword").removeClass("error");
		$("#confirmPasswordErrMsg").text("*");
		confirmPasswordFlag = true;
		towPasswordFlag = true;
	}
	
	if(oldPasswordFlag && newPasswordFlag && confirmPasswordFlag && towPasswordFlag){
		return true;
	} else {
		return false;
	}
}

function checkOldPassword(){
	if($("#oldPassword").val().replace(/\s+/g,'') == ""){
		$("#oldPassword").addClass("error");
		$("#oldPasswordErrMsg").text("<s:text name='OldPasswordIsNull' />");
		$("#oldPassword").focus();
		return;
	} else {
		$("#oldPassword").removeClass("error");
		$("#oldPasswordErrMsg").text("*");
	}
	
	top.showProgress("<s:text name='LoadingCheckPassword' />....");
	
	var ajaxUrl = "../ajax/checkPassword.action?id="+$("#id").val()+"&password="+$("#oldPassword").val();
	$.getJSON(ajaxUrl,function(data){
		if(data){
			$("#oldPassword").removeClass("error");
			$("#oldPasswordErrMsg").text("*");
		} else {
			$("#oldPassword").addClass("error");
			$("#oldPasswordErrMsg").text("<s:text name='OldPasswordIsWrong' />");
			$("#oldPassword").focus();
		}
		
		top.hideProgress();
	});
}
</script>
</head>

<body>
<form id="submitForm" name="submitForm" action="updatePassword.action" method="post" onsubmit="return formSubmit()">
	<input id="id" name="id" type="hidden" value="${account.id }" />
	<table width="100%" cellspacing="1" cellpadding="5" class="table_class">
		<tr>
			<td width="20%"><s:text name='AccountName' />：</td>
			<td>
				<input id="accountName" name="accountName" type="text" readonly="readonly" value="${account.name }" />
				<span id="accountNameErrMsg" class="inputMsg">*</span>
			</td>
		</tr>
		<tr>
			<td width="20%"><s:text name='OldPassword' />：</td>
			<td>
				<input id="oldPassword" name="oldPassword" type="password" value="" onblur="checkOldPassword()"/>
				<span id="oldPasswordErrMsg" class="inputMsg">*</span>
			</td>
		</tr>
		<tr>
			<td width="20%"><s:text name='NewPassword' />：</td>
			<td>
				<input id="newPassword" name="newPassword" type="password" value="" />
				<span id="newPasswordErrMsg" class="inputMsg">*</span>
			</td>
		</tr>
		<tr>
			<td width="20%"><s:text name='ConfirmPassword' />：</td>
			<td>
				<input id="confirmPassword" name="confirmPassword" type="password" value="" />
				<span id="confirmPasswordErrMsg" class="inputMsg">*</span>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input id="submitBtn" name="submitBtn" type="button" onclick="formSubmit();" value="<s:text name='Save' />" />
				<input id="submitBtn" name="submitBtn" type="button" onclick="closeWin();" value="<s:text name='Close' />" />
			</td>
		</tr>
	</table>
</form>
</body>

</html>
